package work20241205.b_duotai;



/**
 * @author zdl
 * @date 2024/12/5
 */
class A {
    public void zhouChang(Graph1 graph) {
        graph.perimeter();

    }
    public void mianJi(Graph1 graph){
        graph.area();
    }
}

class Graph1 {
    private int a;
    private int b;

    public void perimeter() {
        System.out.println("1111");
    }

    public void area() {
    }

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

    public int getB() {
        return b;
    }

    public void setB(int b) {
        this.b = b;
    }
}

class Square extends Graph1 {
    @Override
    public void perimeter() {
        System.out.println("正方形周长=" + (getA() + getB()) * 2);
    }

    @Override
    public void area() {
        System.out.println("正方形面积=" + (getA() * getB()));
    }
}

class Rectangle extends Graph1 {
    @Override
    public void perimeter() {
        System.out.println("长方形周长=" + (getA() + getB()) * 2);
    }

    @Override
    public void area() {
        System.out.println("长方形面积=" + (getA() * getB()));
    }
}

class Circle extends Graph1 {
    int r;

    @Override
    public void perimeter() {
        System.out.println("圆的周长=" + (2 * 3.14 * r));
    }

    @Override
    public void area() {
        System.out.println("圆形面积=" + (3.14 * r * r));
    }

    public int getR() {
        return r;
    }

    public void setR(int r) {
        this.r = r;
    }
}

public class Demo1 {
    //（多态）写一个函数，接受一个图形作为参数，打印出该图形的周长和面积
    public static void main(String[] args) {
        Circle circle = new Circle();
        circle.setR(3);
        Square square = new Square();
        square.setA(2);
        square.setB(2);
        Rectangle rectangle = new Rectangle();
        rectangle.setA(3);
        rectangle.setB(2);
        A a = new A();
        a.zhouChang(square);
        a.zhouChang(rectangle);
        a.zhouChang(circle);
        a.mianJi(square);
        a.mianJi(rectangle);
        a.mianJi(circle);
    }

}
